package com.zhenbao.service.goods.service.impl;

import com.zhenbao.service.goods.dao.SpecMapper;
import com.zhenbao.service.goods.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SpecServiceImpl implements SpecService {
    @Autowired
    private SpecMapper specMapper;

    /**
     * 根据商品的类别来查询商品的规格
     * @param categoryName
     * @return
     */
    public List<Map> findSpecListByCategoryName(String categoryName) {
        List<Map> specList = specMapper.findSpecListByCategoryName(categoryName);
        for (Map map : specList) {
            String[] options = ((String) map.get("options")).split(",");
            map.put("options",options);
        }
        return specList;
    }
}
